#! /bin/csh

alias rm rm
alias mv mv


set n = 1

#
# specify categories
#
echo ""
rm dbase.tmp
rm ../categories/*
touch dbase.tmp
foreach cats  ( `cat categories.txt` )

set catword  = $cats

nawk  -F^ ' BEGIN {  } \
{ \
if ( $10 ~ /'"$catword"'/ ) print $0 \
}' /var/opt/WWW/NCSA/htdocs/sunsoft/catlink/bin/dbase.isv >> /var/opt/WWW/NCSA/htdocs/sunsoft/catlink/bin/dbase.tmp


#
# make text page
#
echo "Creating text home page $catword..."
echo " "

rm ../categories/$catword.txt.html
set letter = "A"

cat head.html > ../categories/$catword.txt.html
echo "<H1>$catword </H1>" >> ../categories/$catword.txt.html
echo "</pre>" >> ../categories/$catword.txt.html
echo "<DL>" >> ../categories/$catword.txt.html
 
echo '<B><FONT size="-1">' >> ../categories/$catword.txt.html
echo '<B>Search for--</b><A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#A">A</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#B">B</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#C">C</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#D">D</A>' >> ../categories/$catword.txt.html
echo '<A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#E">E</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#F">F</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#G">G</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#H">H</A>' >> ../categories/$catword.txt.html
echo '<A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#I">I</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#J">J</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#K">K</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#L">L</A>' >> ../categories/$catword.txt.html
echo '<A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#M">M</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#N">N</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#O">O</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#P">P</A>' >> ../categories/$catword.txt.html
echo '<A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#Q">Q</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#R">R</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#S">S</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#T">T</A>' >> ../categories/$catword.txt.html
echo '<A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#U">U</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#V">V</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#W">W</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#X">X</A>' >> ../categories/$catword.txt.html
echo '<A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#Y">Y</A> <A HREF="/sunsoft/catlink/categories/'$catword'.txt.html#Z">Z</A>' >> ../categories/$catword.txt.html
echo '</FONT></B>' >> ../categories/$catword.txt.html
echo '<hr>' >> ../categories/$catword.txt.html
echo '<p>' >> ../categories/$catword.txt.html


nawk -F^ ' BEGIN {i=65;s=0;letter ="^A.*";rletter = "A"} {\
comp = $1;$7 = $1;href = gsub (/ /,"",$7) \
if ( comp !~ letter ) {\
for ( x=i;x<=100; ++x ){\
letter = sprintf("^%c.*", x)\
rletter = sprintf("%c", x)\
if ( comp ~ letter ) {i=x;s=0;break}\
}\
}\
if ( comp ~ letter && s==0 ) {\
print "<DT><A NAME=\""rletter"\"><B><B>"rletter"</B></B></A><br><DD><a href=/cgi-bin/cat.pl/?"$7"+"$4"><B>"$1"</B></a>"$6"<br>";s=2 \
}\
if ( comp ~ letter && s==1) {\
print "     <DD><a href=/cgi-bin/cat.pl/?"$7"+"$4"><B>"$1"</B></a>"$6"<br>"\
}\
s=1\
}' dbase.tmp  >> ../categories/$catword.txt.html


cat tail.html >> ../categories/$catword.txt.html 

rm dbase.tmp
end


# make main txt 
echo " Making full txt list ..."
echo "" 
 
cat head.html > ../categories/main.txt.html
echo "<H1>Companies by name </H1>" >> ../categories/main.txt.html
echo "</pre>" >> ../categories/main.txt.html
echo "<DL>" >> ../categories/main.txt.html
echo '<B><FONT size="-1">' >> ../categories/main.txt.html
echo '<B>Search for--</b><A HREF="/sunsoft/catlink/categories/main.txt.html#A">A</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#B">B</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#C">C</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#D">D</A>' >> ../categories/main.txt.html
echo '<A HREF="/sunsoft/catlink/categories/main.txt.html#E">E</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#F">F</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#G">G</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#H">H</A>' >> ../categories/main.txt.html
echo '<A HREF="/sunsoft/catlink/categories/main.txt.html#I">I</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#J">J</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#K">K</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#L">L</A>' >> ../categories/main.txt.html
echo '<A HREF="/sunsoft/catlink/categories/main.txt.html#M">M</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#N">N</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#O">O</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#P">P</A>' >> ../categories/main.txt.html
echo '<A HREF="/sunsoft/catlink/categories/main.txt.html#Q">Q</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#R">R</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#S">S</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#T">T</A>' >> ../categories/main.txt.html
echo '<A HREF="/sunsoft/catlink/categories/main.txt.html#U">U</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#V">V</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#W">W</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#X">X</A>' >> ../categories/main.txt.html
echo '<A HREF="/sunsoft/catlink/categories/main.txt.html#Y">Y</A> <A HREF="/sunsoft/catlink/categories/main.txt.html#Z">Z</A>' >> ../categories/main.txt.html
echo '</FONT></B>' >> ../categories/main.txt.html
echo '<hr>' >> ../categories/main.txt.html
echo '<p>' >> ../categories/main.txt.html

nawk -F^ ' BEGIN {i=65;s=0;letter ="^A.*";rletter = "A"} {\
comp = $1;$7 = $1;href = gsub (/ /,"",$7) \
if ( comp !~ letter ) {\
for ( x=i;x<=100; ++x ){\
letter = sprintf("^%c.*", x)\
rletter = sprintf("%c", x)\
if ( comp ~ letter ) {i=x;s=0;break}\
}\
}\
if ( comp ~ letter && s==0 ) {\
print "<DT><A NAME=\""rletter"\"><B>"rletter"</B></A><br><DD><a href=/cgi-bin/cat.pl/?"$7"+"$4"><B>"$1"</B></a>"$6"<br>";s=2 \
}\
if ( comp ~ letter && s==1) {\
print "     <DD><a href=/cgi-bin/cat.pl/?"$7"+"$4"><B>"$1"</B></a>"$6"<br>"\
}\
s=1\
}' dbase.isv  >> ../categories/main.txt.html
 
cat tail.html >> ../categories/main.txt.html



#
# Prepare report directory for push
#

rm -f /var/opt/WWW/NCSA/htdocs/sunsoft/catlink/report/lstwk*
rm -f /var/opt/WWW/NCSA/htdocs/sunsoft/catlink/report/testisv*

touch /var/opt/WWW/NCSA/htdocs/sunsoft/catlink/report/testisv.html









exit 0
